define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'song/index' + location.search,
                    add_url: 'song/add',
                    edit_url: 'song/edit',
                    del_url: 'song/del',
                    multi_url: 'song/multi',
                    import_url: 'song/import',
                    table: 'song',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'category.name', title: __('所属分类'), operate: 'LIKE'},
                        // {field: 'category_id', title: __('Category_id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'singer', title: __('Singer'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'video', title: __('Video'), operate: false,formatter:function (val,data) {
                        //         return '<video style="width: 200px;height: 140px" src="'+val+'" controls="controls"></video>';
                        //     }},
                        // {field: 'learn_file', title: __('Learn_file'), operate: false,
                        //     formatter:function (val,data) {
                        //         return '<video style="width: 200px;height: 50px" src="'+val+'" controls="controls"></video>';
                        //     }
                        // },
                        // {field: 'ai_file', title: __('Ai_file'), operate: false, 
                        // formatter:function (val,data) {
                        //         return '<video style="width: 200px;height: 50px" src="'+val+'" controls="controls"></video>';
                        //     }
                            
                        // },
                        // {field: 'back_file', title: __('Back_file'), operate: false, 
                        // formatter:function (val,data) {
                        //         return '<video style="width: 200px;height: 50px" src="'+val+'" controls="controls"></video>';
                        //     }
                            
                        // },
                        // {field: 'song_file', title: __('Song_file'), operate: false, formatter:function (val,data) {
                        //         return '<video style="width: 200px;height: 50px" src="'+val+'" controls="controls"></video>';
                        //     }},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [
                        
                        	{
                        		
                        		name: 'learnsong',
                        		title: __('歌词教唱'),
                        		text: '歌词教唱',
                        		classname: 'btn btn-xs btn-info btn-dialog',
                        		icon: 'fa fa-eye',
                        		url: 'song/learnsong'
                        	},
                        	{
                        		
                        		name: 'aisong',
                        		title: __('AI唱谱'),
                        		text: 'AI唱谱',
                        		classname: 'btn btn-xs btn-info btn-dialog',
                        		icon: 'fa fa-eye',
                        		url: 'song/aisong'
                        	},
                        	

                        	], 
                        formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        learnsong: function () {
            Controller.api.bindevent();
        },
        
        aisong: function () {
            Controller.api.bindevent();
        },
        
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                $(document).on("fa.event.appendfieldlist", "#second-table .btn-append", function (e, obj) {
                    //绑定动态下拉组件
                    Form.events.selectpage(obj);
                    //绑定日期组件
                    Form.events.datetimepicker(obj);


                });
                Form.api.bindevent($("form[role=form]"));

            }
        }
    };
    return Controller;
});
